import request from "@/utils/request";

const LOG_BASE_URL = "/api/v1/logs";

const LogAPI = {
  getPage(queryParams: LogPageQuery) {
    return request<any, PageResult<LogPageVO[]>>({
      url: `${LOG_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },

  getVisitTrend(queryParams: VisitTrendQuery) {
    return request<any, VisitTrendVO>({
      url: `${LOG_BASE_URL}/visit-trend`,
      method: "get",
      params: queryParams,
    });
  },

  getVisitStats() {
    return request<any, VisitStatsVO[]>({
      url: `${LOG_BASE_URL}/visit-stats`,
      method: "get",
    });
  },
};

export default LogAPI;

export interface LogPageQuery extends PageQuery {
  keywords?: string;
  createTime?: [string, string];
}

export interface LogPageVO {
  id: number;
  module: string;
  content: string;
  requestUri: string;
  method: string;
  ip: string;
  region: string;
  browser: string;
  os: string;
  executionTime: number;
  operator: string;
}

export interface VisitTrendVO {
  dates: string[];
  pvList: number[];
  uvList: number[];
  ipList: number[];
}

export interface VisitTrendQuery {
  startDate: string;
  endDate: string;
}

export interface VisitStatsVO {
  title: string;
  type: "pv" | "uv" | "ip";

  todayCount: number;
  totalCount: number;
  growthRate: number;
}
